//
//  LeftViewController.m
//  UI_Custom
//
//  Created by yutao on 15/2/12.
//  Copyright (c) 2015年 yutao. All rights reserved.
//

#import "LeftViewController.h"

@interface LeftViewController ()

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //创建tableView
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height ) style:UITableViewStylePlain];
    //tableview的风格  没有中间的横线
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];

    
}
#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    //4行
    return 4;
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CellIdentifier";
    //使用自定义cell
    LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil) {
        cell = [[LeftTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
 
    //第一行
    if (indexPath.row == 0) {
        //cell背景图片 (前段)
        cell.titleImageView.image = [UIImage imageNamed:@"news_menu.png"];
        //cell背景图片(后段)
        cell.centerImageView.image = [UIImage imageNamed:@"news_info_back3.png"];
        
        cell.titleLabel.text = @"新闻快讯";

    }
    //第二行
    if (indexPath.row == 1) {
        
        cell.titleImageView.image = [UIImage imageNamed:@"product_menu.png"];
        cell.centerImageView.image = [UIImage imageNamed:@"product_info_back3.png"];
        cell.titleLabel.text = @"游闻汽车";
        
    }
    //第三行
    if (indexPath.row == 2) {
        
        cell.titleImageView.image = [UIImage imageNamed:@"J@HJXO1}@FY249I)DBN5H_N.jpg"];
        cell.centerImageView.image = [UIImage imageNamed:@"live_info_back3.png"];
        cell.titleLabel.text = @"   设置";
        
    }
    //第四行
    if (indexPath.row == 3) {
        
        cell.titleImageView.image = [UIImage imageNamed:@"more_menu.png"];
        cell.centerImageView.image = [UIImage imageNamed:@"more_info_back3.png"];
        cell.titleLabel.text = @"我的收藏";
        
    }
    return cell;
    
}

//- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section {
//    return @"Left Controller";
//}


#pragma mark - UITableViewDelegate
//点击cell触发效果
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //获取到抽屉容器对象，当然也可以用单例来进行存取 但就是不能重新alloc，alloc之后是新的内存地址，就不是最初设置的抽屉框架了
    
    
    //注意：这里的AppDelegate.h的引用 用的是UI_Custom-Prefix.pch预编译文件
    /*创建预编译文件步骤：
     1. command + n -> iOS Other -> PCH File 
     2.在工程的 Build Settings -> 搜索Prefix 填写如下命令
     工程根路径/工程文件名/预编译文件名
    $(SRCROOT)/UI_Custom/UI_Custom-Prefix.pch
     3.在预编译文件中填写如下 #ifdef条件编译语句
     
     #ifdef __OBJC__
     #import<UIKit/UIKit.h>
     #import<Foundation/Foundation.h>
     #import<QuartzCore/QuartzCore.h>
     
     #import"AppDelegate.h"
     #endif
     
     */
    
    DDMenuController *menuController = (DDMenuController*)((AppDelegate*)[[UIApplication sharedApplication] delegate]).menuController;
    
    
    /* 分步获取 得到DDMenuController容器对象
    AppDelegate *appdele = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    DDMenuController *dd = appdele.menuController;
    
     http://blog.csdn.net/huifeidexin_1/article/details/7792371
    */
    

    /*用单例来获取容器对象
    DDMenuController *menuController = [DataHandle shareDataHandle].menuController;
    */
    
    
    // 设置根视图
    if (indexPath.row == 0) {
        
        NewViewController *controller = [[NewViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"新闻快讯"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"news_title_bar.png"] forBarMetrics:UIBarMetricsDefault];
        //进入对应的页面(已经封装)
        [menuController setRootController:navController animated:YES];


    }
    if (indexPath.row == 1) {
        
       CarViewController *controller = [[CarViewController   alloc] init];
        controller.title = [NSString stringWithFormat:@"游闻汽车"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"product_title_bar .png"] forBarMetrics:UIBarMetricsDefault];
        [menuController setRootController:navController animated:YES];

    }
    if (indexPath.row == 2) {
        
        SettingViewController  *controller = [[SettingViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"设置"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"live_title_bar.png"] forBarMetrics:UIBarMetricsDefault];
        [menuController setRootController:navController animated:YES];

    }
    if (indexPath.row == 3) {
        
        AboutOurViewController *controller = [[AboutOurViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"我的收藏"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"more_title_bar.png"] forBarMetrics:UIBarMetricsDefault];
        
        [menuController setRootController:navController animated:YES];
        
    }

    
    //不加此句时 在二级页面返回时 此行会由选中状态慢慢变成非选中状态
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return   self.view.frame.size.height/4;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
